const Icon = require("../models/icon")

// 根据分类获取图标
exports.getIconsByCategory = async (req, res) => {
  try {
    const { category } = req.query

    if (!category) {
      return res.status(400).json({
        success: false,
        error: "缺少分类参数",
      })
    }

    const icons = await Icon.find({ category })
      .sort({ createdAt: -1 })
      .select("-__v")

    res.status(200).json({
      success: true,
      count: icons.length,
      data: icons,
    })
  } catch (err) {
    res.status(500).json({
      success: false,
      error: "服务器错误",
    })
  }
}
